﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using System.Collections.Generic;
using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Web.Paper;
using PowerCreator.LMS.Paper.Entiry;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Config;


public partial class Theme_3_Course : PowerCreator.LMS.Web.Base.WebBasePage
{


    ManagerPaper opPaper = new ManagerPaper();
    PowerCreator.LMS.Web.Course.Course opCourse = new PowerCreator.LMS.Web.Course.Course();
    PowerCreator.LMS.Web.Catalog.Catalog opCatalog = new PowerCreator.LMS.Web.Catalog.Catalog();
    PowerCreator.LMS.Web.Course.Resource opResource = new PowerCreator.LMS.Web.Course.Resource();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    protected string HtmlPublicCourse = "";
    private int pagesize = 6;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = config.GetLanagerValueByKey("theme_menu_Public", PowerCreator.LMS.Language.LanagetItemType.Page);
        if (!IsPostBack)
        {

            string search = GetSearch();
            HtmlPublicCourse = BinderCourse(search, 1);
            BinderPager(search);
        }
    }





    protected override void InitPage()
    {
        //btn_Search.Text = config.GetLanagerValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_Lanager_Notity.Text = GetLanageValueByKey("lbl_Lanager_Notity", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private string GetSearch()
    {
        string search = "CourseIsCompulsory = 3 and CourseState = 1";
        return search;
    }

    private string BinderCourse(string search, int pageIndex)
    {
        string Html = "";
        //公开课程
        PowerCreator.LMS.Web.Course.Course opCourse = new PowerCreator.LMS.Web.Course.Course();
        //string search = "CourseIsCompulsory = 3 and CourseState = 1";
        string orderList = "CourseCreatetime desc,CourseId desc";
        DataTable dt = opCourse.QueryCourse(search, orderList, pagesize, pageIndex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                Html += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                Html += "<tr>";
                Html += "<td valign=\"top\"  style=\"width:168px;\"><table width=\"168\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                Html += "<tr>";
                Html += " <td>";
                    Html += "<a href=\"OpenCourse.aspx?CourseID=" + dt.Rows[i]["Course_ID"].ToString() + "&ProjectID=0\">";
                Html += "<img alt=\"mc\" src=\"" + dt.Rows[i]["CourseImgUrl"].ToString() + "\" width=\"160\" height=\"120\" style=\"border: 1px solid #99CCFF\" />";
                    Html += "</a>";

                Html += "</td>";
                Html += "</tr>";
                Html += "</table></td>";

                Html += "<td align=\"left\"><div class=\"center3ct\">";
                Html += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" align=\"center\">";
                Html += "<tr>";
                Html += "<td>";

                    Html += "<a href=\"OpenCourse.aspx?CourseID=" + dt.Rows[i]["Course_ID"].ToString() + "&ProjectID=0\">";
                Html += dt.Rows[i]["CourseName"].ToString();
                    Html += "</a>";
                Html += "</td>";
                Html += "</tr>";
                Html += "<tr>";
                Html += "<td>";
                Html += " <p>" + config.GetLanagerValueByKey("lbl_AddCourseInfo_TeacherName", PowerCreator.LMS.Language.LanagetItemType.Page) + "：" + PowerCreator.LMS.Common.Utils.StringUtils.GetSubstringLue(dt.Rows[i]["CourseMostlyTeacherName"].ToString(), 4) + "</p>";
                Html += "<p> " + config.GetLanagerValueByKey("lbl_AddCourseInfo_CoursePeriod", PowerCreator.LMS.Language.LanagetItemType.Page) + "：" + dt.Rows[i]["CoursePeriod"].ToString() + " </p>";
                Html += "<p> " + PowerCreator.LMS.Common.Utils.StringUtils.GetSubstringLue(dt.Rows[i]["Description"].ToString(), 72) + " </p>";

                Html += "</td>";
                Html += " </tr>";

                Html += "</table>";
                Html += "</div></td>";
                Html += "</tr>";
                Html += "</table>";
                Html += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
			Html += "<tr><td height=\"2\"></td></tr>";
              Html += "<tr>";
                Html += "<td class=\"xx1\"></td>";
             Html += " </tr>";
			 Html += " <tr><td height=\"2\"></td></tr>";
             
           Html += " </table>";

        }
        return Html;
    }


    private void BinderPager(string search)
    {
        AspNetPager1.PageSize = pagesize;
        AspNetPager1.RecordCount = opCourse.QueryCourseCount(search);
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        HtmlPublicCourse = BinderCourse(search, AspNetPager1.CurrentPageIndex);
    }


 }
